<?php
require_once('lib/db_connection.php');
$tids = $_GET["tids"];
$veh_id = $_GET["veh_id"];
if($tids!="")
{
 $or = "flag_used=0";
 $tids = explode(',',$tids);
 foreach($tids as $tid)
 {
  $or .= " OR autoid='".$tid."'";
 }
 $query_trouble = "SELECT * FROM veh_trouble_tbl WHERE veh_id='".$veh_id."' AND comp_id='".$_SESSION['company_id']."' AND (".$or.") ORDER BY start_date, autoid";
}
if($tids=="")
{
$query_trouble = "SELECT * FROM veh_trouble_tbl WHERE veh_id='".$veh_id."' AND flag_used=0 AND comp_id='".$_SESSION['company_id']."' ORDER BY start_date, autoid";
}
$result_trouble = mysql_query($query_trouble) or die("SELECT TROUBLE ".mysql_error());
//die($query_trouble);
?>
<html>


<head>
<script type='text/javascript' src='js/select_trouble.js'></script>
<link rel="stylesheet" type="text/css" href="css/grid.css" />
</head>

<body onLoad='checkIt()' style="background-color:black">
<!--<div style='width:600px;border-style:solid;'>-->
<div style='width:600px;'><img border="0" src="image/select_trouble.png" width="1079" height="28" />
<br />
<table border='0' style='width:550;margin-left:25px;margin-right:25px;'>
<tr>
  <th style='width:120px'>Date</th>
  <th style='width:240px'>Trouble</th>
  <th style='width:240px'>Remedy</th>
</tr>
 <?php
 $str_ids = "";
 while($row_trouble = mysql_fetch_array($result_trouble))
 {
  $str_ids .= "'".$row_trouble["autoid"]."',";
  $query_trouble_caption = "SELECT value from trouble_droplist_tbl WHERE autoid='".$row_trouble["trouble"]."'";
  $result_caption = mysql_query($query_trouble_caption) or die("SELECT CAPTION ".mysql_error());
  $row_caption = mysql_fetch_array($result_caption);
 ?>
 <tr>
  <td><input id='check<?php echo $row_trouble["autoid"]?>' type='checkbox'/><?php echo $row_trouble["start_date"]?></td>
  <td><?php echo $row_caption["value"]?></td>
  <td><?php echo $row_trouble["remedy"]?></td>
 </tr>
 <?php
 }
 $str_ids = substr($str_ids,0,-1);
 ?>
</table>
<br />
<input type='button' style='background-color:black;color:white;cursor:pointer;margin-left:25px' value='Submit' onClick=pasamo("<?php echo $str_ids ?>") />
<input type='button' style='background-color:black;color:white;cursor:pointer' value='Close' onClick='window.close()'/>
</div>
</body>
</html>